// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   ChartAndroidGraphics.java

package com.java4less.rchart.gc.android;

import android.graphics.*;
import com.java4less.rchart.gc.*;

// Referenced classes of package com.java4less.rchart.gc.android:
//			ChartAndroidColor, ChartAndroidFont, ChartAndroidImage

public class ChartAndroidGraphics extends ChartGraphics
{

	private Canvas graphics;
	private ChartColor color;
	private ChartFont font;
	private boolean antialiasing;

	public ChartAndroidGraphics(Object g)
	{
		font = null;
		antialiasing = true;
		graphics = (Canvas)g;
	}

	public void setColor(ChartColor color)
	{
		this.color = color;
	}

	public void setFont(ChartFont font)
	{
		this.font = font;
	}

	public ChartColor getColor()
	{
		return color;
	}

	public ChartFont getFont()
	{
		return font;
	}

	public void drawArc(int x, int y, int w, int h, int a1, int a2)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setColor(((ChartAndroidColor)color).getColor());
		p.setStyle(android.graphics.Paint.Style.STROKE);
		graphics.drawArc(new RectF(x, y, x + w, y + h), a1 - 180, a2, false, p);
	}

	public void drawLine(int x1, int y1, int x2, int y2)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setColor(((ChartAndroidColor)color).getColor());
		p.setStyle(android.graphics.Paint.Style.STROKE);
		graphics.drawLine(x1, y1, x2, y2, p);
	}

	public int getFontHeight(ChartFont font)
	{
		Paint p = new Paint();
		if (font == null)
			font = new ChartAndroidFont(Typeface.SERIF);
		p.setTypeface(((ChartAndroidFont)font).getFont());
		p.setTextSize(((ChartAndroidFont)font).getSize());
		return (int)(Math.abs(p.getFontMetrics().top) + Math.abs(p.getFontMetrics().bottom));
	}

	public int getFontWidth(ChartFont font, String s)
	{
		Paint p = new Paint();
		if (font == null)
			font = new ChartAndroidFont(Typeface.SERIF);
		p.setTypeface(((ChartAndroidFont)font).getFont());
		p.setTextSize(((ChartAndroidFont)font).getSize());
		float widths[] = new float[s.length()];
		int w = 0;
		p.getTextWidths(s, widths);
		for (int i = 0; i < widths.length; i++)
			w += (int)widths[i];

		return w;
	}

	public boolean drawRotatedText(ChartFont descFont, ChartColor descColor, String txt, int angle, int x, int y, boolean b)
	{
		drawString(txt, x, y);
		return true;
	}

	public void paintRotatedImage(ChartImage srcImage, int angle, int x, int y, int alignment)
	{
		drawImage(srcImage, x, y);
	}

	public void drawString(String s, int x, int y)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setColor(((ChartAndroidColor)color).getColor());
		p.setStyle(android.graphics.Paint.Style.STROKE);
		p.setTypeface(((ChartAndroidFont)font).getFont());
		p.setTextSize(((ChartAndroidFont)font).getSize());
		graphics.drawText(s, x, y, p);
	}

	public void drawImage(ChartImage image, int x, int y)
	{
		if (image == null)
			return;
		android.graphics.Bitmap i = ((ChartAndroidImage)image).getImage();
		if (i == null)
		{
			return;
		} else
		{
			Paint p = new Paint();
			graphics.drawBitmap(i, x, y, p);
			return;
		}
	}

	public void drawImage(ChartImage image, int x1Dest, int y1Dest, int x2Dest, int y2Dest, int x1Source, int y1Source, 
			int x2Source, int y2Source)
	{
		long start = System.currentTimeMillis();
		android.graphics.Bitmap i = ((ChartAndroidImage)image).getImage();
		if (i == null)
		{
			return;
		} else
		{
			Paint p = new Paint();
			graphics.drawBitmap(i, new Rect(x1Source, y1Source, x2Source, y2Source), new Rect(x1Dest, y1Dest, x2Dest, y2Dest), p);
			return;
		}
	}

	public void fillPolygon(int x1[], int y1[], int count)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setStyle(android.graphics.Paint.Style.FILL);
		p.setColor(((ChartAndroidColor)color).getColor());
		Path path = new Path();
		path.moveTo(x1[0], y1[0]);
		for (int i = 1; i < count; i++)
			path.lineTo(x1[i], y1[i]);

		path.lineTo(x1[0], y1[0]);
		graphics.drawPath(path, p);
	}

	public void fillRect(int x1, int y1, int w, int h)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setStyle(android.graphics.Paint.Style.FILL);
		p.setColor(((ChartAndroidColor)color).getColor());
		graphics.drawRect(new RectF(x1, y1, x1 + w, y1 + h), p);
	}

	public void drawPolygon(int x1[], int y1[], int count)
	{
		Paint p = new Paint();
		p.setStyle(android.graphics.Paint.Style.STROKE);
		p.setAntiAlias(antialiasing);
		p.setColor(((ChartAndroidColor)color).getColor());
		for (int i = 1; i < count; i++)
			graphics.drawLine(x1[i - 1], y1[i - 1], x1[i], y1[i], p);

		graphics.drawLine(x1[0], y1[0], x1[count - 1], y1[count - 1], p);
	}

	public void drawRect(int x1, int y1, int w, int h)
	{
		super.drawRect(x1, y1, w, h);
	}

	public void createFadeArea(ChartColor colorFrom, ChartColor colorUntil, int x, int y, int w, int h, boolean vertical, 
			boolean cyclic)
	{
		setColor(colorFrom);
		fillRect(x, y, w, h);
	}

	public void fillArc(int x, int y, int w, int h, int a1, int a2)
	{
		Paint p = new Paint();
		p.setAntiAlias(antialiasing);
		p.setColor(((ChartAndroidColor)color).getColor());
		p.setStyle(android.graphics.Paint.Style.FILL);
		if (a1 == 0 && a2 == 360)
			graphics.drawArc(new RectF(x, y, x + w, y + h), a1, a2, false, p);
		int centerY = y + h / 2;
		int centerX = x + w / 2;
		Path path = new Path();
		path.moveTo(centerX, centerY);
		path.arcTo(new RectF(x, y, x + w, y + h), a1 - 180, a2);
		path.lineTo(centerX, centerY);
		graphics.drawPath(path, p);
	}

	public void setAlpha(float f)
	{
	}

	public void setAlphaComposite(Object obj)
	{
	}

	public Object getAlphaComposite()
	{
		return null;
	}

	public void setLineStyle(int style)
	{
		super.setLineStyle(style);
	}

	public void setLineWidth(int w)
	{
		super.setLineWidth(w);
	}
}
